<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" type="text/css" href="lib/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="css/main.css">
    <link rel="stylesheet" type="text/css" href="css/init.css">
    <link rel="stylesheet" type="text/css" href="css/index.css">
    <script src="lib/jquery.js"></script>
    <script src="lib/bootstrap.min.js"></script>
    <script type="text/javascript" language="javascript">
        function keyLogin() {
            if (event.keyCode == 13)   //回车键的键值为13
                document.getElementById("input1").click();  //调用登录按钮的登录事件
        }


        function login() {

            var openhref = "../WPD/login/userLogin.do";
            var username = document.getElementById("username").value;
            var password = document.getElementById("password").value;
            var COOKIE_NAME = "username";

            if (username == '') {
                alert("用户名不能为空");
                return false;
            }
            if (password == '') {
                alert("密码不能为空");
                return false;
            }
            $.ajax({
                type: "POST",
                async: false,
                dataType: "json",
                url: openhref,
                xhrFields: {
                    withCredentials: true
                },
                crossDomain: true,
                data: {
                    "userCode": username,
                    "userPassword": password
                },
                success: function (data, code, xhr) {
                    if (data.code == 0) {
                        sessionStorage.user = JSON.stringify(data.data);
                        window.location.href = "../WPD/index.html";
                    } else {
                        alert(data.message);
                    }
                }, error: function (XMLHttpRequest, textStatus, errorThrow) {
                    console.log(errorThrow);
                }
            });
        }

    </script>
</head>
<body onkeydown="keyLogin();">
<div class="box-login table bg-attach-ment">
    <div class="table-cell" style="vertical-align: middle;">
        <div class="login-box">
            <div class="lb-det">
                <h2 class="tc">用户登录</h2>
                <ul>
                    <li class="pr input">
                        <i class="icon-user"></i>
                        <input type="text" placeholder="用户名" id="username"/>
                    </li>
                    <li class="pr input">
                        <i class="icon-lock"></i>
                        <input type="password" placeholder="密码" id="password"/>
                    </li>
                    <li class="tc mt22 btn-list">
                        <a href="#" class="ib" id="input1" onclick="login();">登录</a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
    <!--table-cell-->
</div>
<!--box-login-->
</body>
</html>
